﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using DevExpress.XtraScheduler;
using DevExpress.Web.ASPxScheduler;


public partial class ProbandoControl : System.Web.UI.Page
{
    private int lastinsertedAppointmentId;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ASPxScheduler1_AppointmentRowInserting(object sender, DevExpress.Web.ASPxScheduler.ASPxSchedulerDataInsertingEventArgs e)
    {
        e.NewValues.Remove("ID");
    }
    protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        SqlConnection connection = (SqlConnection)e.Command.Connection;
        using (SqlCommand cmd = new SqlCommand("SELECT IDENT_CURRENT('CarScheduling')", connection)) {


            object result = cmd.ExecuteScalar();

            if (result != DBNull.Value)
            {

                this.lastinsertedAppointmentId = Convert.ToInt32(result);

            }

        }
    }
    protected void ASPxScheduler1_AppointmentRowInserted(object sender, DevExpress.Web.ASPxScheduler.ASPxSchedulerDataInsertedEventArgs e)
    {
        e.KeyFieldValue = this.lastinsertedAppointmentId;

    }
    protected void ASPxScheduler1_AppointmentsInserted(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e)
    {
        Appointment apt = (Appointment)e.Objects[0];
        ASPxSchedulerStorage storage = (ASPxSchedulerStorage)sender;
        storage.SetAppointmentId(apt, lastinsertedAppointmentId);
    }
}